package NWish.properties.materials
{
	import away3d.materials.AnimatedBitmapMaterial;

	public class AnimatedBitmapMaterialProperties extends BitmapMaterialProperties
	{
		public function AnimatedBitmapMaterialProperties(parent,materialPropertiesTypes)
		{
			super(parent,materialPropertiesTypes);
			
			var keys
			= 
				[
					'loop'
					,'autoPlay'
					,'frameTime'
					,'index'
					,new AnimateMapProperties(parent)
				];
			addPropertieKeys('Animated',keys);
			
			addPropertieKeys_read('Animated',['playing']);
		}
		
		//
		override public function toString()
		{
			return 'AnimatedBitmapMaterial';
		}
		
		override public function get type()
		{
			return AnimatedBitmapMaterial;
		}
	}
}
import NWish.Logger;
import NWish.json.OrderDict;
import NWish.properties.Properties;

import away3d.materials.AnimatedBitmapMaterial;


class AnimateMapProperties
{
	private var _parent;
	
	public function AnimateMapProperties(parent)
	{
		_parent = parent;
	}
	
	public function propertiesToDict(mat:AnimatedBitmapMaterial,dict:OrderDict,read_only,saving = false)
	{
		if(read_only == false)
		{
			if(mat.extra == null)
				mat.extra = [];
			
			dict.push('AnimateTextures',mat.extra);

			/*if(saving == false)
			{
				var textures = fileSystem.getFileNames('.jpg','.png');
				dict.push(Properties.readMark + 'textuers', textures);
			}*/
		}
		else
		{
		}
	}
	
	public function dictToProperties(dict,mat:AnimatedBitmapMaterial,scene,isloading)
	{
		var ats = dict['AnimateTextures'];
		
		if(ats is Array)
		{
			var newats = []
			var bmds = []
			for each(var a in ats)
			{
				var dm = fileSystem.getResource(a);
				
				if(dm)
				{
					bmds.push(dm);
					newats.push(a);
				}
			}
			
			mat.setMaps(bmds);
			mat.extra = newats;
		}
	}
	
	public function get fileSystem()
	{
		if(_parent)
		{
			return _parent.getPlugin('FileSystem');
		}
	}
	
}
